package org.andhy.formeasy.valve;

import java.util.Set;

public class MultipleValve extends BaseValve {
	
	public final static String IDENTIFY = "multiple";
	
	public final static String SEPARATOR = "," ;
	
	private int count = 1;
	public void invoke(Object value, Set<String> msgHold) {
		if(value == null || msgHold == null){
			return;
		}
		String[] values = value.toString().split(SEPARATOR);
		if(values.length > count){
			msgHold.add(this.getErrorMSG());
		}
		for(String v : values){
			this.invokeNext(v, msgHold);
		}
	}
	
	public void setCount(int count){
		if(count > 1){
			this.count = count;
		}
	}
}
